import React, {PureComponent} from "react"
import cs from "classnames"
import AppMenu from "./component/menu"
import {Route, Switch} from "react-router-dom"
import "./index.less"
import menus from "menus"
import AppHeader from "./component/header"
import {AppContext} from "../../shared/context/app-context"
import loading from "../../shared/libs/loading";
import AppCompose from "./app-compose"
import DynamicFont from 'react-dynamic-font'
import Profile from "./component/profile"
import {createRoute} from "./menu-creator"

const AppContainer = loading(() => import("./component/container"))
const NotFound = loading(() => import("../errors/404"))
const SalesmanForm = loading(() => import("../account/components/SalesmanForm"));
const AccountForm = loading(() => import("../account/components/AccountForm"));
const SalesManagerForm = loading(() => import("../account/components/SalesManagerForm"))
const ProductForm = loading(() => import("../product/components/ProductForm"));
const ProductFormMuti = loading(() => import("../product/components/ProductFormMuti"));
export default @AppCompose
class App extends PureComponent {

	render() {
		const {
			menuCollapsed,
			setMenuCollapsed,
			userInfo,
			setUserInfo,
			location,
			getUserInfo,
			userInfoBusy
		} = this.props

		const {pathname} = location
		const contextValue = {
			menuCollapsed,
			setMenuCollapsed,
			userInfo,
			setUserInfo,
			pathname,
			userInfoBusy,
			refreshUser: getUserInfo
		}

		const clazz = cs({
			"zr-app-home": true,
			//菜单是否收起
			"collapsed": menuCollapsed
		})

		return (
			<AppContext.Provider value={contextValue}>
				<div className={clazz}>
					<div className='left'>
						<div className={cs({"zr-header": true, "hidden": menuCollapsed})}>
							<div>
								<DynamicFont content={'业务报价辅助系统'}/>
							</div>
						</div>
						<Profile/>
						<AppMenu/>
					</div>
					<div className='right' id={'app-container-right'}>
						<AppHeader/>
						<AppContainer>
							<Switch>
								{createRoute(menus())}
								<Route exact={true} component={SalesmanForm} path={`/app/account/salesman/add`}/>
								<Route exact={true} component={SalesmanForm} path={`/app/account/salesman/edit/:id`}/>
								<Route exact={true} component={AccountForm} path={`/app/account/admin/add`}/>
								<Route exact={true} component={AccountForm} path={`/app/account/admin/edit/:id`}/>
								<Route exact={true} component={SalesManagerForm} path={`/app/account/salesman_manager/add`}/>
								<Route exact={true} component={SalesManagerForm} path={`/app/account/salesman_manager/edit/:id`}/>
								<Route exact={true} component={ProductForm} path={`/app/product/add`}/>
								<Route exact={true} component={ProductForm} path={`/app/product/edit/:id`}/>
								<Route exact={true} component={ProductFormMuti} path={`/app/product/addcopy`}/>
								<Route exact={true} component={ProductFormMuti} path={`/app/product/editcopy/:id`}/>
								<Route component={NotFound}/>
							</Switch>
						</AppContainer>
					</div>
				</div>
			</AppContext.Provider>
		)
	}
}


